package day3.demo1_练习;

import java.util.concurrent.*;

public class Test {
    public static void 同步调用(String[] args)throws Exception {
        long begin = System.currentTimeMillis();
        long s1 = new TaskA().process();
        long s2 = new TaskB().process();
        System.out.println("任务1用时："+s1+",任务2用时："+s2+",共用时："+(System.currentTimeMillis()-begin));
    }

    public static void main(String[] args) throws Exception{
        long l = System.currentTimeMillis();
        ThreadPoolExecutor pool = new ThreadPoolExecutor(2,
                4,
                3,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                new ThreadPoolExecutor.DiscardOldestPolicy());

        Future<Long> f1 = pool.submit(new TaskA()::process);
        Future<Long> f2 = pool.submit(new Callable<Long>() {
            @Override
            public Long call() throws Exception {
                return new TaskB().process();
            }
        });
        System.out.println("任务1用时："+f1.get()+",任务2用时："+f2.get()+",共用时："+(System.currentTimeMillis()-l));
    }
}
